<template>
  <!-- 模块1 -->
  <div class="modular">
    <div class="modular_top">
      <div class="triangle"></div>
      <div class="modular_icon">
        <img src="@/assets/img/zl.png" alt="">
      </div>
      <h2>能耗总览</h2>
    </div>
    <div class="loss_cont">
      <div class="loss_title">
        <h2><img src="@/assets/img/jnhn.png" alt="">今年能耗（KWh）</h2>
      </div>
      <div class="fontStyle">
        <div class="item" v-for="(item, index) in strSplit" :key="index">{{ item }}</div>
      </div>
      <div class="loss_box_cont">
        <div class="loss_box">
          <h2>今日能耗</h2>
          <span>{{ this.arrData.day_elec_cnt }}</span>
        </div>
        <div class="loss_box">
          <h2>本月能耗</h2>
          <span>{{ this.arrData.month_elec_cnt }}</span>
        </div>
        <div class="loss_box">
          <h2>今日均时能耗</h2>
          <span>{{ this.arrData.day_per }}</span>
        </div>
        <div class="loss_box">
          <h2>本月均时能耗</h2>
          <span>{{ this.arrData.month_per }}</span>
        </div>
        <div class="loss_box">
          <h2>今日千吨水能耗</h2>
          <span>{{ this.arrData.day_elec_water_per }}</span>
        </div>
        <div class="loss_box">
          <h2>本月千吨水能耗</h2>
          <span>{{ this.arrData.month_elec_water_per }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import * as api from '@/assets/utils/api.js'
export default {
  data() {
    return {
      myChart: {},
      arrData: [],
      strSplit: [],
      index: ''
    }
  },
  async created() {
    const id = { tenantid: 1128 }
    const res = await api.total(id)
    this.arrData = res.data[0]
    this.strSplit = (res.data[0].year_elec_cnt + '').split('')
    this.index = (res.data[0].year_elec_cnt + '').indexOf('.')
  },
  watch: {
    'index'() {
      this.$nextTick(() => {
        if(document.querySelectorAll('.fontStyle .item')[this.index]){
          document.querySelectorAll('.fontStyle .item')[this.index].className = 'itemChange'
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.loss_cont {
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
  padding: 0.55rem 0.15rem 0 0.15rem;

  .loss_title {
    h2 {
      color: #fff;
      font-size: 0.18rem;
      display: flex;
      align-items: center;

      img {
        width: 0.15rem;
        margin: 0 0.05rem 0 -0.05rem;
      }
    }
  }

  .fontStyle {
    display: flex;
    padding-top: 0.1rem;

    .item {
      font-family: 'loss';
      font-size: 0.4rem;
      background: linear-gradient(180deg, #41D9FF 0%, #419EFE 99.5849609375%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      width: 0.35rem;
      height: 0.5rem;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
      margin: 0 0.02rem;

      &::before {
        content: '';
        position: absolute;
        bottom: 0;
        width: 100%;
        height: 45%;
        background: url("@/assets/img/onebj.png") no-repeat center;
      }

      &::after {
        content: '';
        position: absolute;
        top: 0;
        width: 100%;
        height: 45%;
        background: url("@/assets/img/onebj.png") no-repeat center;
      }
    }

    .itemChange {
      width: 0.15rem;
      height: 0.5rem;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 0.4rem;
      background: linear-gradient(180deg, #41D9FF 0%, #419EFE 99.5849609375%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
  }

  .loss_box_cont {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding-top: 0.2rem;

    .loss_box {
      width: 49.5%;
      margin-bottom: 0.02rem;
      background: url("@/assets/img/yjjx.png") no-repeat center;
      background-size: 100% 100%;
      height: 0.35rem;
      display: flex;
      justify-content: space-between;
      align-items: center;

      // padding: 0 0.12rem;
      h2 {
        color: #BDE2FF;
        font-size: 0.15rem;
        padding-left: 0.13rem;
        padding-top: 0.07rem;
      }

      span {
        font-family: 'Pang';
        font-weight: 400;
        font-style: italic;
        font-size: 0.16rem;
        padding-right: 0.13rem;
        padding-top: 0.05rem;
        color: #EED55F;
      }

      &:nth-child(3),
      &:nth-child(4) {
        span {
          color: #39E0BE;
        }
      }

      &:nth-child(5),
      &:nth-child(6) {
        span {
          color: #53BBF0;
        }
      }
    }
  }
}
</style>
